<style>
#AddFolderButton{
	margin-left: 16px;
}
#AddFolderTable td{
	padding-top: 16px;
}
#AddFolderTable input{
	padding: 4px;
}
</style>

<table class='FrameTable' id='AddFolderTable'>
	<tr><td><v-text id='FolderText' title='目录名称' maxlength='16' size='16'></v-text></td></tr>
	<tr style='display:none'><td><v-select id='EnabledSelect' title='修改标志' option='可编辑|可展示'></v-select></td></tr>
	<tr><td><v-icon title='目标图标' path='menu' id='FolderIcon'></v-icon><v-button id='AddFolderButton' title='添加'></v-button></td></tr>
</div>

<script>
getVue('AddFolderTable');

$('#FolderIcon').css('background-image', 'url(/res/img/menu/folder.png)');
$('#EnabledSelect').attr('disabled', true);
$('#FolderText').focus();

$('#AddFolderButton').click(function(){
	var folder = $('#FolderText').val();
	var enabled = $('#EnabledSelect').val();
	var icon = getBackgroundImage(getCtrl('FolderIcon'));
	
	enabled = (parseInt(enabled) ? 1 : 2);
	
	if ((len = strlen(folder)) == 0){
		showToast('请输入目录名称');
		$('#FolderText').focus();
	}
	else if (len > 16){
		showToast('目录名称最多8个汉字或16个英文字母');
		$('#FolderText').focus();
	}
	else if (!isFileName(folder)){
		showToast('目录名称不能包含特殊字符');
		$('#FolderText').focus();
	}
	else if (hasSubmenu(folder)){
		showToast('目录名称与现有目录冲突');
		$('#FolderText').focus();
	}
	else{
		var param = {};
		param['flag'] = 'C';
		param['icon'] = getString(icon);
		param['folder'] = getString(folder);
		param['enabled'] = getString(enabled);

		getHttpResult('/editmenu', param, function(data){
			if (data.code == XG_TIMEOUT){
				sessionTimeout();
			}
			else if (data.code == XG_AUTHFAIL){
				showNoAccessToast();
			}
			else if (data.code < 0){
				showToast('添加菜单目录失败');
			}
			else{
				updateSubmenu();
			}
		});
	}
});
</script>
